def count(self,s): result = '' count = 0 char = '#' for i in s: if i!=char: if char!='#': result+=str(count)+char char = i count = 1 else: count+=1 result += str(count)+char return result def countAndSay(self, n): """ :type n: int :rtype: str """ s='1' for i in range(1, n): s=self.count(s) return s